package org.example.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.erp.domain.Workshop;
import org.example.erp.domain.Workstation;
import org.example.erp.mapper.WorkshopMapper;
import org.example.erp.service.WorkshopService;
import org.example.erp.service.WorkstationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 86180
 * @description 针对表【workshop(车间设置)】的数据库操作Service实现
 * @createDate 2024-11-08 15:04:19
 */
@Service
public class WorkshopServiceImpl extends ServiceImpl<WorkshopMapper, Workshop>
        implements WorkshopService {

    @Autowired
    WorkstationService workstationService;

    public List<Workshop> find() {
        return baseMapper.findworkshop();
    }

    @Override
    public boolean deleteDetails(List<String> id) {
        boolean success = true;
        for (String s : id) {
            QueryWrapper<Workstation> q = new QueryWrapper<>();
            q.lambda().in(Workstation::getWorkshopCode, s);
            if (workstationService.count(q) > 0) {
                success = false;
            } else {
                boolean b = removeById(s);
                if (!b) {
                    success = false;
                    break;
                }
            }
        }
        return success;
    }
}




